export const commonMixin = {
  computed:{

  },
  data(){
    return {
      form:{
        isFuse: false,
        isTrend: false,
        isAwait: false,
        isTrace: false,
        isRelease: false,
        direction: "up",
      }
    }
  },
  filters: {
	  fixed(v, scale){
		  if(v){
			  if(!scale){
				  scale = 2
			  }
			  return parseFloat(v).toFixed(scale)
		  }
		  return v
	  },
    getGridName(type){
      let name = ''
      type += ''
      switch(type){
        case '1':
          name = 'ai金字塔'
          break
        case '2':
          name = '智能高频'
          break
        case '3':
          name = '现货网络'
          break
        case '4':
          name = '现货金字塔'
          break
      }
      return name
    },
    getGridStatus(type) {
      let name = ''
      type += ''
      switch(type){
        case '0':
          name = '未启动'
          break
        case '-1':
          name = '删除'
          break
        case '1':
          name = '启动'
          break
        case '2':
          name = '暂停'
          break
        case '3':
          name = '停止'
          break
      }
      return name
    }
  },
  methods: {
    hello(){
      console.log('hello yide')
    },
    jump(url) {
      this.$u.func.route(url)
    },
    sectionChange(index) {
      this.curNow = index;
    },
    // form 表单方法
    funding(e){ this.form.funding = e },
    firstNumber(e){ this.form.firstNumber = e },
    maxTimes(e){ this.form.maxTimes = e },
    closeRate(e){ this.form.closeRate = e },
    openPriceOne(e){ this.form.openPriceOne = e },
    openNumOne(e){ this.form.openNumOne = e },
    openPriceTwo(e){ this.form.openPriceTwo = e },
    openNumTwo(e){ this.form.openNumTwo = e },
    openPriceThree(e){ this.form.openPriceThree = e },
    openNumThree(e){ this.form.openNumThree = e },
    rangeDown(e){ this.form.rangeDown = e },
    rangeUp(e){ this.form.rangeUp = e },
    awaitRetreatRate(e){ this.form.awaitRetreatRate = e },
    traceRetreatRate(e){ this.form.traceRetreatRate = e },

    openRate(e){ this.form.openRate = e },       // spot-contract
    maxPosition(e){ this.form.maxPosition = e }, // spotnetwork
    // dropdown
    changeMarket(e){
      console.log('changeMarket', e, this.marketList[e-1])
      this.form.marketId = this.marketList[e-1].value
      this.initCoin()
    },
    changeCoin(e){
      console.log('changeCoin', e, this.coinList[e])
      this.form.baseCurrency = this.coinList[e].baseCurrency
      this.form.quoteCurrency = this.coinList[e].quoteCurrency
      console.log('baseCurrency',this.form.baseCurrency)
      console.log('quoteCurrency',this.form.quoteCurrency)
    },
    initMarket(){
      this.$http.get('app/t-strategy-market').then(res => {
        this.marketList = res.map(i => ({
          label:i.text,
          value:i.id
        }))
        this.form.marketId = this.marketList[0].value
        this.initCoin()
      })
    },
    initMarket2(){
      this.$http.get('app/t-strategy-market').then(res => {
        this.marketList = res.map(i => ({
          label:i.text,
          value:i.id
        }))
        
      })
    },
    initCoin(){
      if(!this.form.marketId){
        return
      }
      let index = -1
      this.$http.get(`app/t-market-currency?marketId=${this.form.marketId}`).then(res => {
        this.coinList = res.map(i => ({
          label:i.baseCurrency+'/'+i.quoteCurrency,
          id:i.id,
          baseCurrency:i.baseCurrency,
          quoteCurrency:i.quoteCurrency,
          value:++index
        }))
        this.form.baseCurrency = this.coinList[0].baseCurrency
        this.form.quoteCurrency = this.coinList[0].quoteCurrency
      })
      index = -1
    },
    initCoin2(){
      if(!this.form.marketId){
        return
      }
      let index = -1
      this.$http.get(`app/t-market-currency?marketId=${this.form.marketId}`).then(res => {
        this.coinList = res.map(i => ({
          label:i.baseCurrency+'/'+i.quoteCurrency,
          id:i.id,
          baseCurrency:i.baseCurrency,
          quoteCurrency:i.quoteCurrency,
          value:++index
        }))
        console.log('coinList', this.coinList)

				// 设置coin选中
				let label = this.form.baseCurrency +"/" +this.form.quoteCurrency
				let coin = this.coinList.find((item) => {
					if(item.label == label){
						console.log(item.label, label)
						return item
					}
				})
				console.log(label, 'coin', coin)
				this.coin = coin.value
      })
      index = -1
    },

    // switch
    fuseChange(e){
      console.log('fuseChange', e)
      this.form.isFuse = e
    },
    trendChange(e) {
      this.form.isTrend = e
    },
    awaitChange(e) {
      this.form.isAwait = e
    },
    traceChange(e) {
      this.form.isTrace = e
    },
    releaseChange(e) {
      this.form.isRelease = e
    },
    // subsection
    subsectionChange(index) {
      this.current = index;
      console.log('subsectionChange', this.current)
      if(this.current == 1){
        this.form.direction = 'down'
      } else {
        this.form.direction = 'up'
      }
    },
  }
}